#include <linux/module.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/miscdevice.h>
#include <linux/kernel.h>
#include <linux/major.h>
#include <linux/mutex.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/stat.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/tty.h>
#include <linux/kmod.h>
#include <linux/gfp.h>
#include <asm/io.h>
#include "led_board.h"


static int major = 0;
static struct class *led_class;


static ssize_t led_drv_read (struct file *file, char __user *buf, size_t size, loff_t *offset){
    return 0;
}

static ssize_t led_drv_write (struct file *file, const char __user *buf, size_t size, loff_t *offset){
    int retval;
    char status;
    retval = copy_from_user(&status, buf, 1);
    led_board_ctrl(status);
    return 1;
}

static int led_drv_open (struct inode *node, struct file *file){
    led_board_init();
    return 0;
}

static int led_drv_close (struct inode *node, struct file *file){
    return 0;
}

static struct file_operations led_drv = {
    .owner = THIS_MODULE,
    .open = led_drv_open,
    .read = led_drv_read,
    .write = led_drv_write,
    .release = led_drv_close,
};


static int __init led_drv_init(void){
    major = register_chrdev(0, "led_drv", &led_drv);
    led_class = class_create(THIS_MODULE, "led_class");
    device_create(led_class, NULL, MKDEV(major, 0), NULL, "led");
    return 0;
}
static void __exit led_drv_exit(void){
    device_destroy(led_class, MKDEV(major, 0));
    class_destroy(led_class);
    unregister_chrdev(major, "led_drv");
}


module_init(led_drv_init);
module_exit(led_drv_exit);
MODULE_LICENSE("GPL");
